package atm;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class GetPanel extends JPanel  implements ActionListener{
    private ATMFrame atmFrame;
    private ImageIcon sure = new ImageIcon("images/buttonSure.jpg");
    private JLabel getMoney = new JLabel("取款金额：");
    private JTextField moneyField = new JTextField();
    private JButton sureBtn = new JButton(sure);
    private Font font = new Font("黑体", Font.BOLD, 20);

    public GetPanel(ATMFrame atmFrame) {
        this.atmFrame = atmFrame;
        this.setLayout(null);
        this.add(sureBtn);
        this.add(getMoney);
        this.add(moneyField);
        getMoney.setBounds(300, 200, 120, 50);
        sureBtn.setBounds(400, 260, 140, 50);
        moneyField.setBounds(400, 200, 140, 50);
        getMoney.setFont(font);
        sureBtn.addActionListener(this);

        this.setOpaque(false);

    }
    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("取款点击"+e.getActionCommand());
        if( e.getSource() == sureBtn){
            User user = atmFrame.getLoginUser();
            try{
                user.setBlance(user.getBlance() - Double.parseDouble(moneyField.getText()));
                System.out.println(user.getBlance());
            }catch (NumberFormatException e1){
                JOptionPane.showMessageDialog(this,"必须输入数字");
                return;
            }



            atmFrame.switchPanel("menu");
        }
    }
}